package com.group.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.group.model.Guess;
import com.group.model.GuessLog;
import com.group.model.User;
import com.group.model.UserTickerLog;

@Repository
public interface GuessDao {

	public int countInProgressGuess(@Param("guessId") Long guessId);

	public List<Guess> queryGuess(@Param("start") Integer start, @Param("limit") Integer limit);

	public int queryGuessCount();

	@Select("select * from `user` u where u.isRobot = 1 limit #{start},#{limit}")
	public List<User> queryRobot(@Param("start") Integer start, @Param("limit") Integer limit);

	@Select("select count(*) from `user` u where u.isRobot = 1")
	public int queryRobotCount();

	@Select("select * from guesslog l where l.userId = #{userId} order by id desc limit #{start},#{limit}")
	public List<GuessLog> queryGuessLog(@Param("userId") Long userId, @Param("start") Integer start, @Param("limit") Integer limit);

	@Select("select count(*) from guesslog l where l.userId = #{userId}")
	public int queryGuessLogCount(@Param("userId") Long userId);

	@Update("update guess g set g.show = 0 where g.show = 1 and g.id != #{arg0}")
	public void setUnShow(Long guessId);

	@Select("select * from `user` u  order by u.winRate desc limit 20")
	public List<User> queryWinRateRank();

	@Select("select * from `user` u  order by u.profit desc limit 20")
	public List<User> queryProfitRank();
	
	@Select("select count(*) from `user` u where u.profit > #{arg0}")
	public int countMyProfitRank(double profit);
	
	@Select("select count(*) from `user` u where u.winRate > #{arg0}")
	public int countMyWinRateRank(double winRate);
	
	@Select("select * from usertickerlog l where l.cid = #{arg0} and l.reason = '提现' and l.state = '已完成' order by id desc limit 20")
	public List<UserTickerLog> queryTopGuessLog(String cid);
}
